#!/usr/bin/lua50

--[[
        generate callback slots C files
        See Copyright Notice in "invoke.h"
]]

max = 64 -- should be enough for everyone ;)

print([[
#include <stdarg.h>
#include "invoke.h"
#include "callback.h"
#include "cbslots.h"

#define decl_slot(N) \
	LL cb_slot##N(long x, ...) { va_list ap; va_start(ap, x); return callback_run(&cb_slots[N], x, ap); }

callback_t cb_slots[MAX_SLOTS];
]])

-- declare the code

for i=1,max do
	print ("decl_slot(" .. i - 1 .. ")")
end
print()

-- declare the slot index

print("void* code_slots[MAX_SLOTS] = {")
for i=1,max do
	if i < max then
		print("\tcb_slot" .. (i - 1) .. ",")
	else
		print("\tcb_slot" .. (i - 1))
	end
end
print("};")
